Skip to content

Add reusable workflow to check external contributor status#78

Open
solace-mdupls wants to merge 11 commits intomainfrom
feat/check-external-contributor
Open

Add reusable workflow to check external contributor status#78
solace-mdupls wants to merge 11 commits intomainfrom
feat/check-external-contributor

Conversation

@solace-mdupls
Copy link
Collaborator

@solace-mdupls solace-mdupls commented Mar 2, 2026

Summary

  • Adds a new reusable workflow that checks if a PR creator is a member of a specified GitHub team
  • If the creator is not a member, automatically adds a configurable label (defaults to "external contributor")
  • This enables repositories to easily identify and track external contributions

Test Plan

  • Workflow created and pushed to feature branch
  • Test the workflow in solace-agent-mesh by checking that external contributors get the label added
  • Verify team membership check works correctly

🤖 Generated with Claude Code

✨ PR Description

What is the purpose of this change?

Add a reusable GitHub Actions workflow to automatically detect and label pull requests from external contributors who are not members of a specified GitHub team, enabling better visibility and differentiated review processes for external contributions.

How is this accomplished?

  • Creates a new reusable workflow (check-external-contributor.yml) that can be called from other workflows with configurable inputs for team slug and label name
  • Implements team membership verification using the GitHub REST API to check if the PR creator belongs to the specified team by comparing their team memberships against the provided team slug
  • Automatically applies a configurable label (defaults to "external contributor") to pull requests when the creator is determined not to be a team member
  • Uses pinned actions/github-script@v7.0.1 (SHA: 60a0d83039c74a4aee543508d2ffcb1c3799cdea) for secure execution of membership checks and label application
  • Sets explicit pull-requests: write permission scope to allow label modifications
  • Includes conditional execution to only run on pull request events and only apply labels when membership check returns false

Anything reviews should focus on/be aware of?

  • The workflow requires a GITHUB_TOKEN secret to be passed from the calling workflow, which needs sufficient permissions to read team memberships and write PR labels
  • The team membership check uses listMembershipsForAuthenticatedUser() API which retrieves teams for the authenticated user (the actor triggering the workflow), not the PR creator - this may need verification to ensure it checks the correct user's membership
  • Consider whether the workflow should handle cases where the team slug doesn't exist or the API call fails (currently no explicit error handling)
  • The workflow only runs on pull request events but doesn't specify which PR activity types (opened, synchronize, reopened, etc.), which may affect when labels are applied

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how

Add a new reusable workflow that checks if a PR creator is a member of a specified GitHub team. If the creator is not a member, the workflow automatically adds a configurable label (defaults to "external contributor") to the PR.

This workflow enables repositories to easily identify and track external contributions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@gitstream-cm gitstream-cm bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ PR Review

The workflow contains a critical logic error that defeats its entire purpose: it checks the workflow bot's team membership instead of the PR creator's membership.

2 issues detected:

🐞 Bug - Team membership check targets the workflow bot instead of the PR creator 🛠️

Details: The workflow uses listMembershipsForAuthenticatedUser() which checks the authenticated bot token's team memberships, not the PR creator's. This means the workflow will never correctly identify external contributors since it's checking the wrong user's membership status.
File: .github/workflows/check-external-contributor.yml (33-39)
🛠️ A suggested code correction is included in the review comments.

🐞 Bug - Required secret GITHUB_TOKEN is defined but not passed to actions that need it

Details: The workflow declares GITHUB_TOKEN as a required secret but never passes it to the github-script actions via the github-token parameter. Both actions will use the default token instead, which may lack necessary org:read permissions for team membership checks. This same issue exists at line 47 for the second github-script action.
File: .github/workflows/check-external-contributor.yml

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how

Comment on lines +33 to +39
const { data: teams } = await github.rest.teams.listMembershipsForAuthenticatedUser();
const teamSlugs = teams.map(team => team.slug);
const teamSlug = '${{ inputs.github_team_slug }}';

const isMember = teamSlugs.includes(teamSlug);
console.log(`Looking for team: ${teamSlug}`);
console.log(`User's teams: ${teamSlugs.join(', ')}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞 Bug - Wrong User Checked: Replace the API call with one that checks the PR creator's team membership. Get the PR creator from context.payload.pull_request.user.login and use github.rest.teams.getMembershipForUserInOrg() with the repository's organization (context.repo.owner), team_slug, and the PR creator's username.

Suggested change
const { data: teams } = await github.rest.teams.listMembershipsForAuthenticatedUser();
const teamSlugs = teams.map(team => team.slug);
const teamSlug = '${{ inputs.github_team_slug }}';
const isMember = teamSlugs.includes(teamSlug);
console.log(`Looking for team: ${teamSlug}`);
console.log(`User's teams: ${teamSlugs.join(', ')}`);
const prCreator = context.payload.pull_request.user.login;
const teamSlug = '${{ inputs.github_team_slug }}';
const org = context.repo.owner;
let isMember = false;
try {
await github.rest.teams.getMembershipForUserInOrg({
org: org,
team_slug: teamSlug,
username: prCreator
});
isMember = true;
} catch (error) {
if (error.status === 404) {
isMember = false;
} else {
throw error;
}
}
console.log(`PR Creator: ${prCreator}`);
console.log(`Looking for team: ${teamSlug}`);
Is this review accurate? Use 👍 or 👎 to rate it

If you want to tell us more, use /gs feedback e.g. /gs feedback this review doesn't make sense, I disagree, and it keeps repeating over and over

@gitstream-cm
Copy link

gitstream-cm bot commented Mar 2, 2026

Please mark whether you used Copilot to assist coding in this PR

  • Copilot Assisted

solace-mdupls and others added 10 commits March 2, 2026 17:02
Add a new GitHub Action that checks if a PR creator is a member of a specified GitHub team.
If the creator is not a member, the action automatically adds a configurable label (defaults
to 'external contributor') to the PR.

This action enables repositories to easily identify and track external contributions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the check-external-contributor workflow since we've converted it to a reusable
GitHub Action (.github/actions/check-external-contributor) which provides better
modularity and consistency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace gh CLI calls with github-script action to ensure proper GitHub API permissions
for adding labels to issues. This resolves 'Resource not accessible by integration' errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move team membership check to github-script to use consistent authentication context.
Add error handling to gracefully handle permission issues - defaults to treating
users as external contributors if membership cannot be verified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use github-script for adding labels to ensure proper authentication and permissions.
This fixes the 'Resource not accessible by integration' error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -0,0 +1,71 @@
name: Check External Contributor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solace-mdupls can we re-home this in the home folder. We wanted to move all the actions on the root-level

Also if you can generate a README.md on the same folder as the action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants